package ship.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ship.entity.orderifm;
import ship.service.shipservice;

/**
 * Servlet implementation class addmyorderifm
 */
@WebServlet("/addmyorderifm")
public class addmyorderifm extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addmyorderifm() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		int number = Integer.parseInt( request.getParameter("snumber"));
		String name = request.getParameter("sname");
		String time = request.getParameter("stime");
		String shipname = request.getParameter("sshipname");
		String shipform = request.getParameter("sshipform");
		String gettime = request.getParameter("sgettime");
		String mode = request.getParameter("smode");
	    orderifm ifm = new orderifm(number,name,time,shipname,shipform,gettime,mode);
	    shipservice service = new shipservice();
	    boolean result = service.addorderifm(ifm);
	    if(result) {
            String mess = "您的订单信息生成成功!";
            request.setAttribute("mess", mess); 
            request.getRequestDispatcher("querymyorderifm").forward(request, response);
	    }else {
            String mess = "您的订单信息生成失败，请联系管理员!";
            request.setAttribute("mess", mess); 
            request.getRequestDispatcher("querymyorderifm").forward(request, response);
    		
	}
	}

}
